/**
 *  Copyright 1.08.2012 oliver.keusemann@googlemail.com
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package de.xelerity.geolessi.types.poi;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class NextAbfahrtsListe extends ArrayList<Abfahrt> {

	private static final long serialVersionUID = 3767572352255972560L;
	long creationTime;

	private static Log log = LogFactory.getLog(NextAbfahrtsListe.class);

	public NextAbfahrtsListe() {
		super();
		creationTime = new Date().getTime();
	}

	public List<Abfahrt> getAbfahrten() {
		return this;
	}

	public long getCreationTime() {
		return creationTime;
	}

	public void setCreationTime(long creationTime) {
		this.creationTime = creationTime;
	}

	public static NextAbfahrtsListe fromAbfahrten(List<Abfahrt> pAbfahrten, long pCurrentTime) {
		if (pAbfahrten == null || pAbfahrten.size() == 0) {
			return new NextAbfahrtsListe();
		}

		NextAbfahrtsListe lRet = new NextAbfahrtsListe();
		lRet.setCreationTime(pCurrentTime);

		for (Abfahrt lDepTime : pAbfahrten) {
			if (!lDepTime.isValid()) {
				log.info("Abfahrt nicht gueltig:" + lDepTime);
				continue;
			}
			lDepTime.calcOffset(pCurrentTime);
			lRet.add(lDepTime);
		}

		return lRet;
	}

}
